/*
* jlb
*/
package com.jlb.count.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.count.entity.Count;
import com.jlb.count.service.CountSV;

/**
 * 统计数据 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/count")
@Slf4j
@Api(value = "统计数据控制器", description = "统计数据控制器")
public class CountCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private CountSV countSV;

    /**
     * 查询Count一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询Count一个详情信息", notes = "查询Count一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(Long id) {
        if (id == null) {
            return null;
        }
        Count count = countSV.load(id);
        log.info(JSON.toJSONString(count));
        return BeanRet.create(true, "查询成功", count);
    }


    /**
     * 根据条件id查询Count一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询Count一个详情信息", notes = "查询Count一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        Count count = countSV.loadById(id);
        log.info(JSON.toJSONString(count));
        return BeanRet.create(true, "查询成功", count);
    }


    /**
     * 查询Count信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询Count信息集合", notes = "查询Count信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore Count count, Integer curPage, Integer pageSize) {
        Page<Count> page = new Page<Count>(pageSize, curPage);
        List<Count> counts = countSV.list(count, page.genRowStart(), page.getPageSize());
        page.setVoList(counts);
        int total = countSV.count(count);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询Count信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询Count信息集合", notes = "查询Count信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(Long id, Integer curPage, Integer pageSize) {
        Page<Count> page = new Page<Count>(pageSize, curPage);
        List<Count> counts = countSV.list(id, page.genRowStart(), page.getPageSize());
        page.setVoList(counts);
        int total = countSV.count(id);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计Count信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计Count信息数量根据主键", notes = " 统计Count信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id) {
        return countSV.count(id);
    }

    /**
     * 统计Count信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计Count信息数量", notes = "统计Count信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "totalJlb", value = "金兰宝产生总数量", paramType = "query"),
            @ApiImplicitParam(name = "costJlb", value = "金兰宝消耗的总数量", paramType = "query"),
            @ApiImplicitParam(name = "totalOre", value = "矿石产生的总数量", paramType = "query"),
            @ApiImplicitParam(name = "costOre", value = "矿石消耗的总数量", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore Count count) {
        if (count == null) {
            return countSV.count(new HashMap());
        } else {
            return countSV.count(count);
        }
    }


    /**
     * 创建Count
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建Count", notes = "创建Count")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "totalJlb", value = "金兰宝产生总数量", paramType = "query"),
            @ApiImplicitParam(name = "costJlb", value = "金兰宝消耗的总数量", paramType = "query"),
            @ApiImplicitParam(name = "totalOre", value = "矿石产生的总数量", paramType = "query"),
            @ApiImplicitParam(name = "costOre", value = "矿石消耗的总数量", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore Count count) {
        countSV.save(count);
        return BeanRet.create(true, "创建成功", count);
    }


    /**
     * 修改Count
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改Count", notes = "修改Count")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "totalJlb", value = "金兰宝产生总数量", paramType = "query"),
            @ApiImplicitParam(name = "costJlb", value = "金兰宝消耗的总数量", paramType = "query"),
            @ApiImplicitParam(name = "totalOre", value = "矿石产生的总数量", paramType = "query"),
            @ApiImplicitParam(name = "costOre", value = "矿石消耗的总数量", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore Count count) {
        countSV.modify(count);
        return BeanRet.create(true, "修改成功", count);
    }

    /**
     * 删除Count
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除Count", notes = "删除Count")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id) {
        countSV.delete(id);
        return BeanRet.create(true, "删除Count成功");
    }

}
